import java.util.*;
public class lk53 {
    public static void main(String[] args) {
        lk53 l=new lk53(); 
        Scanner sc= new Scanner(System.in);
        int n=sc.nextInt();
        int[] a=new int[n];
        for(int i=0;i<n;i++){
            a[i]=sc.nextInt();
        }
        int m=l.maxSubArray(a);
        System.out.println(m);
    }
    public int maxSubArray(int[] nums) {
        int n=nums.length;
        int all=0;
        
        for(int i=0;i<n;i++){
            all+=nums[i];
        }
        int max=all;System.out.println(all);
        int left=0;int right=n-1;
        while(left<right){
            int t1=left,t2=right;
            if(nums[left]>nums[right]){
                all-=nums[right];
                if(all>max){
                    max=all;
                }
                right--;
            }else if(nums[left]<nums[right]){
                all-=nums[left];
                if(all>max){
                    max=all;
                }
                left++;
            }else while(left>right){
                left++;
                right--;
                all-=nums[right];
                if(all>max){
                    max=all;
                }
                if(nums[left]>nums[right]){
                    all-=nums[right];
                    if(all>max){
                        max=all;
                    }
                    left=t1;
                    right--;
                    break;
                }
                if(nums[left]<nums[right]){
                    all-=nums[left];
                    if(all>max){
                        max=all;
                    }
                    left++;
                    right=t2;
                    break;
                }
            }
            
        }
        all-=nums[left];
        if(all>max){
            max=all;
        }
        return max;
    }
}
